package com.zoke.daycarpool.view;

import android.content.Context;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

import com.zoke.daycarpool.R;
import com.zoke.support.base.BaseDialog;

public class AppDialog extends BaseDialog {

	private EditText mEdit;
	private Button mFirstBtn;
	private Button mSecondBtn;

	public AppDialog(Context context) {
		super(context);
	}

	@Override
	protected int getLayoutRes() {
		return R.layout.dialog_appdialog;
	}

	/** 设置副标题 **/
	public void setSubTitle(CharSequence text) {
		TextView subTv = new TextView(getContext());
		subTv.setTextSize(14);
		subTv.setText(text);
		subTv.setTextColor(getContext().getResources().getColor(
				R.color._content));
		setSubContent(subTv);
	}

	public BaseDialog hideLeftBtn() {
		mLeftBtn.setVisibility(View.GONE);
		return this;
	}

	/** 隐藏右侧按钮 **/
	public BaseDialog hideRightBtn() {
		mRightBtn.setVisibility(View.GONE);
		return this;
	}

	/** 设置选择view--两项选择时调用 **/
	public BaseDialog setchoseView(ChoseItemClick item) {
		View choseView = mInflater.inflate(R.layout.include_dialog_sex, null);
		mFirstBtn = (Button) choseView.findViewById(R.id.sub_first_btn);
		mSecondBtn = (Button) choseView.findViewById(R.id.sub_second_btn);
		setSubContent(choseView);
		hideLeftBtn();
		hideRightBtn();
		setOnItemClick(item);
		return this;
	}

	/** 设置第一个文本 **/
	public void setChoseFirstText(CharSequence text) {
		if (mFirstBtn != null)
			mFirstBtn.setText(text);
	}

	/** 设置第2个文本 **/
	public void setChoseSecText(CharSequence text) {
		if (mFirstBtn != null)
			mSecondBtn.setText(text);
	}

	public Button getChoseFirst() {
		return mFirstBtn;
	}

	public Button getChoseSecond() {
		return mSecondBtn;
	}

	private void setOnItemClick(final ChoseItemClick item) {
		if (item == null)
			return;
		if (mFirstBtn == null || mSecondBtn == null)
			return;
		mFirstBtn.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				item.onItemClick(0, mFirstBtn);
				AppDialog.this.dismiss();
			}
		});
		mSecondBtn.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				item.onItemClick(1, mSecondBtn);
				AppDialog.this.dismiss();
			}
		});
	}

	public interface ChoseItemClick {
		void onItemClick(int position, View view);
	}

	// /** 填充Edit **/
	// protected BaseDialog setSubEdit() {
	// View subEt = mInflater.inflate(R.layout.include_dialogedit, null);
	// mEdit = (EditText) subEt.findViewById(R.id._dialog_et);
	// setSubContent(subEt);
	// return this;
	// }

	// /** 设置输入框文本 **/
	// public void setEditText(CharSequence text) {
	// if (mEdit == null)
	// setSubEdit();
	// mEdit.setText(text);
	// }
	//
	// /** 设置edit的hint 要在设置Edit以后 **/
	// public void setEditHint(CharSequence hint) {
	// if (mEdit == null)
	// setSubEdit();
	// mEdit.setHint(hint);
	// }

	// /**获取文本框文字 **/
	// public String getEditText() {
	// if (mEdit == null)
	// setSubEdit();
	// return mEdit.getText().toString();
	// }
	//
	// /** 获取编辑框控件 **/
	// public EditText getEditView(){
	// if (mEdit == null)
	// setSubEdit();
	// return mEdit;
	// }

}
